package com.billing.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.billing.model.dao.MessageMapper;
import com.billing.model.entity.CrmCustomer;
import com.billing.model.entity.Message;
import com.billing.model.entity.MessageAppBean;
import com.billing.service.MessageService;

@Service
public class MessageServiceImpl implements MessageService {

	@Resource
	private MessageMapper messagemapper;

	@Override
	public List<Message> selectmessgeList(String title, String cont, String status,
			String startDate, String endDate, int organizationid, int currentPage, int pageSize) {
		return messagemapper.selectmessgeList(title, cont, status, startDate, endDate, organizationid,
				currentPage, pageSize);
	}

	@Override
	public int selectmessgeNum(String title, String cont, int organizationid) {
		return messagemapper.selectmessgeNum(title, cont, organizationid);
	}

	@Override
	public int insertMessage(Message message) {
		return messagemapper.insertMessage(message);
	}

	@Override
	public Message selectmessgebyId(String id) {
		return messagemapper.selectmessgebyId(id);
	}

	@Override
	public int updateMessage(Message message) {
		return messagemapper.updateMessage(message);
	}

	@Override
	public int deleteMessage(String id) {
		return messagemapper.deleteMessage(id);
	}

	@Override
	public int examineMessage(String id) {
		return messagemapper.examineMessage(id);
	}

	@Override
	public List<Message> selectexamine() {
		return messagemapper.selectexamine();
	}

	@Override
	public Map<String, Object> selMessageId(int pageSize,int currentPage) {
		int totalNum = messagemapper.InterfaceNum();
		int totalPage = totalNum / pageSize;
		if (totalNum % pageSize != 0) {
			totalPage++;	
		}
		totalPage = totalPage <= 0 ? 1 : totalPage;
		currentPage = currentPage > totalPage ? totalPage : currentPage;
		
		List<MessageAppBean> list = messagemapper.selMessageId((currentPage - 1) * pageSize, pageSize);
		Map<String, Object> map = new HashMap<>();
		map.put("totalNum", totalNum);
		map.put("totalPage", totalPage);
		map.put("total", totalPage);
		map.put("list", list);
		return map;
		
		//return messagemapper.selMessageId(userid,currentPage,pageSize);
	}

	@Override
	public int AuditData(Message message) {
		return messagemapper.AuditData(message);
	}

	@Override
	public int modifyState(String id) {
		return messagemapper.modifyState(id);
	}

	/*@Override
	public List<Message> selrecyclebin(int organizationid, int currentPage,
			int pageSize) {
		return messagemapper.selrecyclebin(organizationid, currentPage, pageSize);
	}*/

	@Override
	public int selrecyclebinNum(int organizationid) {
		return messagemapper.selrecyclebinNum(organizationid);
	}

	@Override
	public List<Message> selrecyclebin() {
		return messagemapper.selrecyclebin();
	}

	@Override
	public Message selMessagebyId(String id) {
		return messagemapper.selMessagebyId(id);
	}

	@Override
	public int ReturnMessage(String id) {
		return messagemapper.ReturnMessage(id);
	}

	@Override
	public int deleteMessageByid(int id) {
		return messagemapper.deleteMessageByid(id);
	}

	@Override
	public int updatereadtype(Message message) {
		return messagemapper.updatereadtype(message);
	}

	@Override
	public Map<String, Object> selUnreadMessageId(String userid, int pageSize,int currentPage) {
		int totalNum = messagemapper.selUnreadNum(userid);
		int totalPage = totalNum / pageSize;
		if (totalNum % pageSize != 0) {
			totalPage++;	
		}
		totalPage = totalPage <= 0 ? 1 : totalPage;
		currentPage = currentPage > totalPage ? totalPage : currentPage;
		
		List<MessageAppBean> list = messagemapper.selUnreadMessageId(userid, (currentPage - 1) * pageSize, pageSize);
		Map<String, Object> map = new HashMap<>();
		map.put("totalNum", totalNum);
		/*map.put("totalPage", totalPage);
		map.put("total", totalPage);*/
		map.put("list", list);
		return map;
	}

}
